perf(compiler): bypass dynamic dispatch for known-array appends - #97
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For known arrays, append expressions such as
$items[] = makeValue()still useoffsetSet(null, tmp)when the RHS needs materialization or the assignment result is used. That dispatches through runtime type/key checks before reachingArray::append.Call
append(tmp)directly forType::ARRAY, retaining the existing RHS temporary and expression result. Dynamic receivers, simple statement fast paths, and explicit reference assignments retain their existing lowering.Adds a code-generation regression test, an executable semantics test covering references, assignment results, copy-on-write and RHS mutation, and a standalone append benchmark with raw measurements and reproduction instructions.
Performance
On Linux ARM64 in Docker, PHP 8.5.10 ZTS, PHPX
6a68f38, GCC-O2without LTO, against baseline692841a6: 100 million appends took a median 980.88 ms before and 563.60 ms after (42.54% less elapsed time). All nine alternating measured pairs were faster after one discarded warm-up pair; checksums matched. This is an append-heavy microbenchmark on a shared development machine, not an application-wide speedup or a claim about native PHP performance.Validation
HotPathCodegenTest: 5 tests, 25 assertions pass; new codegen test fails against the original trait.array-append-expression,array-statement-write-optimized, andarray-value-write-dereferences-source.git diff --checkpasses. Full-suite and cross-platform validation were not run.